
import commProtocol.*;

public class TestEntities {

public static void main(String args[])
{
  try {
	  // creates a contact
	  Contact yo = new Contact("lolo", "192.168.1.1");
  
	  // creates a Hello message and converts to a byte array
	  Hello hola = new Hello(yo, false);
	  byte[] b1 = Message.toByteArray(hola);
  
	  // creates a Chat message and converts to a byte array
	  Texte chacha = new Texte(yo,"chachacha");
	  byte[] b2 = Message.toByteArray(chacha);
  
	  // retrieves the Hello Message
	  Message m = Message.getMessage(b1, 0, b1.length);
	  if (m instanceof Hello) {
		  Hello h = (Hello) m;
		  System.out.println(h);
	  }
  
	  // retrieves the Chat Message
	  m = Message.getMessage(b2, 0, b2.length);
  
	  if (m instanceof Texte) {
		  Texte c = (Texte) m;
		  System.out.println(c);
	  }
  }
  catch (Exception ex) {
	  ex.printStackTrace();
  }
}
}